package com.juyu.miliao.scheduler.service.impl;

import com.juyu.miliao.common.util.CommonUtil;
import com.juyu.miliao.scheduler.service.HomeVideoRabbitService;
import com.juyu.miliao.scheduler.service.UpdateHomeVideoService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author jh
 * 2018/8/3
 */
@Component
public class HomeVideoRabbitServiceImpl implements HomeVideoRabbitService {

    // TODO:jh 2018/8/3 可以考虑加入策略,不会立马更新,要不然可能更新太频繁了

    @Resource
    private UpdateHomeVideoService updateHomeVideoService;

    @RabbitListener(queues = "home.video.id")
    @RabbitHandler
    @Override
    public void receiverVideo(String videoId) {
        Long id = CommonUtil.null2Long(videoId);
        if (id > 0L) {
            updateHomeVideoService.updateByVideoId(id);
        }
    }

    @RabbitListener(queues = "home.user.id")
    @RabbitHandler
    @Override
    public void receiverUser(String userId) {
        Long id = CommonUtil.null2Long(userId);
        if (id > 0L) {
            updateHomeVideoService.updateByUserId(id);
        }
    }

}
